<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\STaskInfo;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class TaskController extends Controller {
	use HasResourceActions;

	/**
	 * Index interface.
	 *
	 * @param Content $content
	 * @return Content
	 */
	public function index(Content $content) {
		return $content
			->header('任务')
			->description('列表')
			->body($this->grid());
	}

	/**
	 * Show interface.
	 *
	 * @param mixed $id
	 * @param Content $content
	 * @return Content
	 */
	public function show($id, Content $content) {
		return $content
			->header('任务')
			->description('详情')
			->body($this->detail($id));
	}

	/**
	 * Edit interface.
	 *
	 * @param mixed $id
	 * @param Content $content
	 * @return Content
	 */
	public function edit($id, Content $content) {
		return $content
			->header('任务')
			->description('编辑')
			->body($this->form()->edit($id));
	}

	/**
	 * Create interface.
	 *
	 * @param Content $content
	 * @return Content
	 */
	public function create(Content $content) {
		return $content
			->header('任务')
			->description('新增')
			->body($this->form());
	}

	/**
	 * Make a grid builder.
	 *
	 * @return Grid
	 */
	protected function grid() {
		$grid = new Grid(new STaskInfo);

		$grid->id('Id')->sortable();
		$grid->title('标题');
		$grid->tags('标签');
		$grid->content('内容');
		$grid->res_url('资源');
		$grid->poster('海报');
		// $grid->admin_id('上传人');
		$grid->created_at('创建时间');
		$grid->updated_at('更新时间');

		return $grid;
	}

	/**
	 * Make a show builder.
	 *
	 * @param mixed $id
	 * @return Show
	 */
	protected function detail($id) {
		$show = new Show(STaskInfo::findOrFail($id));

		$show->id('Id');
		$show->title('标题');
		$show->tags('标签');
		$show->content('内容');
		$show->res_url('资源');
		$show->poster('海报');
		// $show->admin_id('上传人');
		$show->created_at('创建时间');
		$show->updated_at('更新时间');
		// $show->deleted_at('Deleted at');

		return $show;
	}

	/**
	 * Make a form builder.
	 *
	 * @return Form
	 */
	protected function form() {
		$form = new Form(new STaskInfo);

		$form->text('title', '标题');
		$form->text('tags', '标签');
		$form->textarea('content', '内容');
		$form->file('res_url', '资源');
		$form->image('poster', '海报');
		$form->hidden('admin_id')->value(\Admin::user()->id);
		$form->footer(function ($footer) {

			// 去掉`查看`checkbox
			$footer->disableViewCheck();

			// 去掉`继续编辑`checkbox
			$footer->disableEditingCheck();

			// 去掉`继续创建`checkbox
			$footer->disableCreatingCheck();

		});
		return $form;
	}
}
